<template>
  <div id="app">
    <h1>{{ $store.state.num }}</h1>
    <br />
    <button @click="addNum">加</button>
    <button v-on:click="subNum">减</button>
    <button @click="asycnAddNum">异步加</button>
    <br />
    <h1>{{isOddAndEven}}</h1>
    <h1>{{localGetter}}</h1>
  </div>
</template>

<script>
import {mapGetters} from 'vuex'

export default {
  data() {
    return {}
  },

  // 计算属性实现
  /* computed:{
    isAddOrOdd:function(){
      return this.$store.getters.isOddAndEven
    }
  },  */

  computed:{
    localGetter:function(){
      return '本地的get'
    },
    ...mapGetters(["isOddAndEven"])
  },
  // 过滤器实现

  methods: {
    addNum: function () {
     this.$store.commit('add')
    },
    subNum: function () {
      this.$store.commit('sub')
    },
    asycnAddNum: function () {
     this.$store.dispatch('asycnAdd')
    },
  },
  name: "App",
  components: {},
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
